package main.java.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo8 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try (Connection connection = DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            System.out.println("请输入用户名");
            String username = sc.nextLine();
            System.out.println("请输入密码");
            String password = sc.nextLine();
            String sql = "SELECT * FROM userinfo WHERE username = '"+username+"' AND password = '"+password+"'";
            ResultSet resultSet = statement.executeQuery(sql);
            System.out.println(resultSet.next()?"登录成功！":"用户名或密码错误！");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
